June Listing 4
         TTL "SPEED/ASM Sample program"
;
;
;
;****************************************
;*                                      *
;*      SPEED/ASM Equates               *
;*                                      *
;****************************************
;
;
;
;
;
;
;
;
; GENERAL PURPOSE EQUATES
;
; The following variable are used
; by the SPEED/ASM package
; and shouldn't be used by the SPEED/ASM
; programmer.
;
;
;
;
FORASAV  EPZ 0
FORXSAV  EPZ FORASAV+1
FORYSAV  EPZ FORXSAV+1
FORZPG   EPZ FORYSAV+1
DESTADR  EPZ FORZPG+2
PTRADR   EPZ DESTADR+2
ISIMMED  EPZ PTRADR+2
OP       EPZ ISIMMED+1
MAXLEN   EPZ OP+2
VALUE    EPZ MAXLEN+1
DIGIT    EPZ VALUE+2
LEAD0    EPZ DIGIT+1
JMPADR   EPZ LEAD0+1
COUNT    EPZ JMPADR+2
GOTLN    EPZ COUNT+1
LINEINDX EPZ GOTLN+1
SIGN     EPZ LINEINDX+1
ACL      EPZ SIGN+1
ACH      EPZ ACL+1
XTNDL    EPZ ACH+1
XTNDH    EPZ XTNDL+1
AUXL     EPZ XTNDH+1
AUXH     EPZ AUXL+1
;
PROMPT   EPZ $33
RNDL     EPZ $4E
RNDH     EPZ $4F
STACK    EQU $100
INPUT    EQU $200
;
;
;
;
;
;
;
;****************
;*  CONSTANTS   *
;****************
;
;
;
; The following symbols are constants
; for the values "FALSE", "TRUE", and
; Carriage Return (respectively).
;
; These symbols should only appear
; as immediate operands to a 6502
; instruction or in the operand field
; of a pseudo-opcode like BYT.
;
;
;
;
;
FALSE    EQU 0
TRUE     EQU 1
CR       EQU $8D
;
;
;
;
;
;
; "IF" STATEMENT EQUATES
;
; The following symbols should only
; be used in the ADR pseudo-opcode
; following a call to the SPEED/ASM
; IFx routines.
;
;
;
EQ       EQU "="
NE       EQU "#"
GT       EQU ">"
LT       EQU "<"
GE       EQU ">"|"="*256
LE       EQU "<"|"="*256
;
;
;
;
;
;
;
;***************************
;* SPEED/ASM ENTRY POINTS  *
;***************************
;
;
;
;
; NOTE: THE EQUATE OF PUTC MUST
; BE CHANGED IF YOU RELOCATE
; SPEED/ASM TO SOME LOCATION
; OTHER THAN $7800
;
;
;
PUTC     EQU $7800
GETC     EQU PUTC+3
SAGL     EQU GETC+3          ;FOR USE BY S/A ONLY- SEE DOC.
SAPC     EQU SAGL+3          ; "   "   "  "   "     "   "
HOME     EQU SAPC+3          ;HOME AND CLEAR
READLN   EQU HOME+3
INIT     EQU READLN+3
FOR      EQU INIT+3
FOR0     EQU FOR+3
NEXT     EQU FOR0+3
IFI      EQU NEXT+3
IFI0     EQU IFI+3
IFS      EQU IFI0+3
IFS0     EQU IFS+3
MOVE     EQU IFS0+3
LOAD     EQU MOVE+3
MOVS     EQU LOAD+3
LDSTR    EQU MOVS+3
PRINT    EQU LDSTR+3
PRTSTR   EQU PRINT+3
PRTINT   EQU PRTSTR+3
RDSTR    EQU PRTINT+3
RDINT    EQU RDSTR+3
ONXGOTO  EQU RDINT+3
CASE     EQU ONXGOTO+3
CASEI    EQU CASE+3
INSET    EQU CASEI+3
NOTINSET EQU INSET+3
ABS      EQU NOTINSET+3
NEG      EQU ABS+3
MUL      EQU NEG+3
DIV      EQU MUL+3
MOD      EQU DIV+3
RND      EQU MOD+3
SUBSTR   EQU RND+3
INDEX    EQU SUBSTR+3
LENGTH   EQU INDEX+3
CONCAT   EQU LENGTH+3
GETWZPG  EQU CONCAT+3        ;USED BY SPEED/ASM
RDFP     EQU GETWZPG+3
PRTE     EQU RDFP+3
PRTF     EQU PRTE+3
FADD     EQU PRTF+3
FSUB     EQU FADD+3
FMUL     EQU FSUB+3
FDIV     EQU FMUL+3
FLT      EQU FDIV+3
FIX      EQU FLT+3
FNEG     EQU FIX+3
FADDTN   EQU FNEG+3
FSUBTN   EQU FADDTN+3
FTIMES   EQU FSUBTN+3
FINTO    EQU FTIMES+3
IFF      EQU FINTO+3
MOVFP    EQU IFF+3
;
;
;
;**********************************
;*                                *
;* SPEED/ASM Sample program #3:   *
;*                                *
;*  This program demonstrates     *
;* some 6502 code that is neces-  *
;* sary for writing SPEED/ASM     *
;* programs. In particular it     *
;* demonstrates how one handles   *
;* character variables in a       *
;* SPEED/ASM program.             *
;*                                *
;* Assembler: LISA 2.5            *
;* Requires SPEED/ASM package.    *
;* Randall Hyde                   *
;*                                *
;**********************************
;
;
;
;
;
EXIT     EQU $FF69           ; Entry point to Apple Monitor.
;
;
;
         JSR INIT            ; Initialize SPEED/ASM
;
;
         JSR HOME            ; Clear the Screen
         JSR PRINT
         BYT CR,CR,"6502--SPEED/ASM Test Program"
         BYT CR,CR
         BYT "ASCII Character Set Table",CR
         BYT "-------------------------"
         BYT CR,CR
         BYT "Character   ASCII Code",CR
         BYT "---------   ----------",CR,CR,0
;
; Init CH to space
;
         LDA #" "
         STA CH
;
; Loop to print the ASCII values
;
PRTASC   LDA CH              ; Emulate the BASIC
         STA I               ; statement "I = ASC(CH)
         LDA #0
         STA I+1
;
         JSR PRINT
         BYT "    ",0
         LDA CH              ;  Print the character
         JSR PUTC
         JSR PRINT
         BYT "   -----  ",0
         JSR PRTINT          ; Print the ASCII Code
         ADR I
;
;
; Print a carriage return to
; move to the next line.
;
         LDA #CR
         JSR PUTC
;
; Add one to the CH value
;
         INC CH              ; 6502 instruction to increment a byte
;
; See if we're done
;
         LDA CH
         CMP #$FF            ; Last ASCII value plus one
         BLT PRTASC
;
;
;
; Read characters from the keyboard
; until a "#" character is pressed.
;
         JSR PRINT
         BYT CR,CR,"Enter any text terminated",CR
         BYT "by a pound sign (""#"")",CR,CR
         BYT ":",0
READLOOP JSR GETC            ; Read the character
         JSR PUTC            ; and print it.
         CMP #"#"            ; Check for "#" character.
         BNE READLOOP        ; If not "#", repeat.
;
;
; The following code prompts the
; person at the keyboard to enter
; "Y" or "N". If something else
; is entered then the code is
; repeated.
;
GETYORN  JSR PRINT
         BYT CR,CR,CR
         BYT "Enter Yes or No (Y/N): ",0
         JSR GETC
         CMP #"Y"
         BEQ GOODANS
         CMP #"N"
         BNE GETYORN
;
GOODANS:
;
;
;
; This code prompts the user to enter
; a decimal value. Once the value
; is entered the ASCII character
; corresponding to that code is
; printed on the screen.
;
;  Entering zero terminates the
; loop.
;
PRTCHR   JSR PRINT
         BYT CR
         BYT CR,"Enter a decimal value in the"
         BYT CR,"range 0..255: ",0
         JSR RDINT
         ADR I
         BVS PRTCHR          ; If an error occured.
;
; Force integer value into the
; range 0..255 by zeroing the high
; order byte.
;
         LDA #0
         STA I+1
;
; Print the decimal value (in case
; they entered too large a number,
;
         JSR PRINT
         BYT CR,"Decimal value: ",0
         JSR PRTINT
         ADR I
         JSR PRINT
         BYT "  ASCII Character: """,0
         LDA I
         JSR PUTC
         LDA #"""
         JSR PUTC
;
; Check the L.O. byte of I to
; see if it is zero.
;
; (On the '6502 BEQ and BNE can
; be used immediately after a
; LDA instruction to see if zero
; was loaded into the accumlator
; or not)
;
         LDA I
         BNE PRTCHR
;
;
; Quit and return to the Apple Monitor
;
         JSR PRINT
         BYT CR,CR,CR
         BYT "End of sample program #3",CR,0
;
;
         JMP EXIT            ;  Return to Apple Monitor
;
CH       DFS 1               ; Char
I        DFS 2               ; Integer
         END